package org.vaadin.vaadinjit.widgetset.client.ui;

import com.google.gwt.core.client.JavaScriptObject;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.UIDL;

public class VJitPieChart extends VJitChartWidget<JitPieChartOverlay> {


	
	/**
	 * The constructor should first call super() to initialize the component and
	 * then handle any initialization relevant to Vaadin.
	 */
	public VJitPieChart() {
		super();
	}
	

	/**
	 * Called whenever an update is received from the server 
	 */
	@Override
	public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
		super.updateFromUIDL(uidl, client);
	}
	
	@Override
	protected native JitPieChartOverlay initJit(JavaScriptObject jitConfig) /*-{
		var elName = jitConfig.injectInto;
		var tipsJson = {  
			enable: true,  
			onShow: function(tip, elem) {  
				$wnd.$jit.fireChartHoverLabel(elName, elem.name);
				tip.innerHTML = "<b>" + elem.name + "</b>: " + elem.value;
			}  
		};
		jitConfig['Tips'] = tipsJson;
		return new $wnd.$jit.PieChart(jitConfig);
	}-*/;
	
	
	@Override
	protected void setupConfig(JitConfiguration config) {
		super.setupConfig(config);
		config.setOption("offset", 30);
		config.setOption("sliceOffset", 0);
		config.setOption("labelOffset", 20);
		config.setOption("showLabels", true);
		config.setOption("resizeLabels", 7);
		
		JitConfiguration label = new JitConfiguration();
		label.setOption("type", getLabelType());
		label.setOption("size", 20);
		label.setOption("family", "Arial");
		label.setOption("color", getTextColor());
		
		config.setOption("Label", label);
	}
	

	
	@Override
	protected native void handleNativeResize(JitPieChartOverlay overlay) /*-{
	    var size = overlay.sb.canvas.getSize(),
        	min = Math.min;
    	overlay.sb.config.levelDistance = min(size.width, size.height)/2 
      		- overlay.config.offset - overlay.config.sliceOffset;
	
		overlay.normalizeDims();
		overlay.sb.refresh();
		overlay.sb.fx.animate({
        	modes: ['node-property:dimArray'],
        	duration:1500
      	});
	}-*/;



}
